<template>
  <div class="tips-container">
    <div class="tips-tool" :class="{ isBottom: isBottom }" v-if="isTool">
      <span>当前共有{{ increase + unit }}未读</span>
      <button @click="handleClick">全部记为已读</button>
    </div>
    <div v-else :class="{ isBottom: isBottom }" class="tips-content">{{ describe }}</div>
  </div>
</template>
<script>
export default {
  props: {
    isTool: {
      type: Boolean,
      default: true,
    },
    increase: {
      type: [Number, String],
      default: 0,
    },
    title: {
      type: String,
      default: ""
    },
    reduce: {
      type: [Number, String],
      default: 0
    },
    isBottom: {
      type: Boolean,
      default: true
    },
    unit: {
      type: String,
      default: "位"
    },
    status: {
      type: String,
      default: "新增"
    }
  },
  computed: {
    describe() {
      let str = ''
      let num = this.increase - this.reduce
      if (num  > 0) {
        str = `比昨日增加了${ num + this.unit }`
      } else if (num < 0) {
        str = `比昨日减少了${ Math.abs(num) + this.unit }`
      } else {
        str = `与昨日相等`
      }
      if (this.increase || this.reduce) {
        return `今日${ this.status + this.increase + this.unit + this.title }，${str}`
      } else {
        return `今日无${this.title}，继续努力哦～`
      }
    }
  },
  methods: {
    handleClick() {
      this.$dialog.confirm({
        overlay: true,
        title: '确定将未读消息全部设为已读吗？',
      }).then(() => {

        this.$emit('on-click')
        // on confirm
      }).catch(() => {
        // on cancel
      })
    }
  }
}
</script>
<style lang="less">
.tips-container {
  .tips-tool {
    display: flex;
    height: 48px;
    padding: 0 16px;
    justify-content: space-between;
    align-items: center;
    background: #F7F9FA;
    margin: 0px;
    span {
      color: #405170;
      font-size: 14px;
    }
    button {
      font-size: 12px;
      font-weight: 400;
      color: #007ae6;
      height: 24px;
      border-radius: 12px;
      border: 1px solid #007ae6;
      background-color: #ffffff;
      padding: 5px 12px;
    }
  }
  .tips-content {
    display: flex;
    height: 40px;
    margin: 0px;
    justify-content: center;
    align-items: center;
    background: #F7F9FA;
    font-size: 12px;
    color: #EA4D2E;
    opacity: 0.7;
  }
  .isBottom {
    margin-bottom: -12px;
  }
}
</style>
